package game.controler;

import game.controler.gestionnaires.conversation.GestionnaireConversation;
import game.gui.panelconversation.PanelConversation;
import game.gui.panelvue.PanelVue;
import game.model.conversation.Conversation;
import game.model.conversation.Dialogue;
import game.model.conversation.Monologue;
import game.model.objets.Fou;
import game.model.objets.Objet;
import java.util.ArrayList;

/**
 *
 * @author Gab'z
 */
public class ControlerPanelConversation {

    private static ControlerPanelConversation controlerPanelConversation = null;
    private static PanelConversation panelConversation;
    private static ArrayList<String> buffer = new ArrayList<String>(0);

    private ControlerPanelConversation() {
        panelConversation = PanelConversation.getPanelConversation();
    }

    public static ControlerPanelConversation getControlerConversation() {
        if (controlerPanelConversation == null) {
            controlerPanelConversation = new ControlerPanelConversation();
        }
        return controlerPanelConversation;
    }

    public static void bufferAdd(String ligne) {
        buffer.add(ligne);
    }

    public static ArrayList<String> getBuffer() {
        return buffer;
    }

    public static void resetBuffer() {
        buffer = new ArrayList<String>(0);
    }

    public static void demarrerConversation(String idConversation) {
        if (idConversation != null) {
            Conversation conversation = GestionnaireConversation.getGconversation().getConversation(idConversation);
            conversation.doActionPostAffichageConversation();
            System.out.println("tentative d'affichage de conversation " + conversation.getId());
            if ("Monologue".equals(conversation.getTypeConversation())) {
                panelConversation.afficherMonologue((Monologue) conversation);
            } else {
                panelConversation.afficherDialogue((Dialogue) conversation);
            }
        } else {
            PanelVue.removeFog();
            panelConversation.removeAll();
            EtatJeu.setConversationEngagee(false);
            
        }
        PanelVue.reloadPanelVue();
        reloadPanelConversation();
    }

    public static void afficherDescription(String description) {
        panelConversation.afficherDescription(description);
        reloadPanelConversation();
    }

    static void afficherDescription(Fou fou) {
        panelConversation.afficherDescription(fou.getDescription());
    }

    static void afficherDescription(Objet objet) {
        panelConversation.afficherDescription(objet.getDescription());
    }

    public static void afficherInfo(String info) {
        panelConversation.afficherInfo(info);
        reloadPanelConversation();
    }

    public static void cleanPanelConversation() {
        panelConversation.removeAll();
        reloadPanelConversation();
    }

    public static void reloadPanelConversation() {
        System.out.println("reloadPanelConversation");

        panelConversation.repaint();
        panelConversation.validate();
    }
}
